package com.shkco.controller;

import com.shkco.dto.ProductDto;
import com.shkco.service.IProductService;
import com.shkco.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private IProductService productService;

    @PostMapping("/add")
    public AjaxResult add(@RequestBody ProductDto productDto) {
        try {
            productService.add(productDto);
            return new AjaxResult();
        } catch (RuntimeException e) {
            e.printStackTrace();
            return new AjaxResult(false,e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }
}
